﻿namespace KseCms.Application
{
    public class SystemAppService : IDynamicApiController
    {
        private readonly ISystemService _systemService;
        public SystemAppService(ISystemService systemService)
        {
            _systemService = systemService;
        }

        public object Login(LoginUserDto user)
        {
            var findUser = _systemService.FindUser(user);

            if (findUser == null)
                throw Oops.Oh(ErrorCodes.not_exist, "User");

            var accessToken = JWTEncryption.Encrypt(new Dictionary<string, object>()
            {
                { "UserId", findUser.Id },
                { "Email",findUser.Email },
            });

            return accessToken;

        }
    }
}